package com.wtwd.device.controller;


import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.vo.CheckAppVersionVo;
import com.wtwd.device.model.vo.RespEntity;
import com.wtwd.device.service.AppDetectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mjy
 * @date 2021/11/11
 * @description
 */

@Api(tags = "app检测模块")
@RestController
@RequestMapping("/app-detection")
public class AppDetectionController {


    private static final Logger logger = LoggerFactory.getLogger(AppDetectionController.class);

    @Autowired
    private AppDetectionService appDetectionService;


    /**
     * 检测app更新
     *
     * @param appName
     * @param appVersion
     * @return
     */
    @ApiOperation(value = "检测app更新", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appName", value = "app名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "appVersion", value = "app当前版本", required = true, dataType = "String"),
            @ApiImplicitParam(name = "clientType", value = "客户端类型1：ios,2:安卓", required = true, dataType = "int")
    })
    @GetMapping("/checkAppVersion")
    public RespEntity<CheckAppVersionVo> checkAppVersion(@RequestParam("appName") String appName,
                                                         @RequestParam("appVersion") String appVersion,
                                                         @RequestParam("clientType") Integer clientType) {
        logger.info("checkAppVersion param" + appName,appVersion);
        if (StringUtils.isBlank(appName)||StringUtils.isBlank(appVersion)){
            return new RespEntity(RespCode.PARAMS_ERROR);
        }
        return appDetectionService.checkAppVersion(appName, clientType, appVersion);
    }



}
